// ============================== 导入依赖 ============================== //

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async remoteList({ state: { API, MAP, param } }) {
    const TIP = API.transTip(MAP.tipList)
    const [num, arr, obj] = await API.getList(param, TIP)
    MAP.COUNT = obj

    const idSet = arr.reduce((set, item) => set.add(item.alarmResId), new Set())
    const id = [...idSet].filter((item) => item && item !== 'null').join()

    const TIP_DEVICE = API.transTip('查询设备经纬度')
    const arrDevice = await API.getList({ ...param, id }, TIP_DEVICE)

    return [num, transList(arr, arrDevice)]
  },
}

// ============================== 转换方法 ============================== //

const transList = (arr, arrDevice) => {
  arr.forEach((item) => {
    const matched = arrDevice.find((device) => device.id === item.alarmResId)
    if (matched) Object.assign(item, { lon: matched.lon, lat: matched.lat })
  })

  return arr.filter((item) => item.lon && item.lat)
}
